package com.dingreading.cloud.admin.controller;

import com.dingreading.cloud.admin.util.redis.RedisService;
import com.dingreading.cloud.common.base.R;
import com.dingreading.cloud.common.util.RedisParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/system/redis")
@Api(tags = "总部-清空redis所有缓存")
public class RedisController {

    @Resource
    private RedisService redisService;

    @ApiOperation(value = "清空活动系统和叮叮学院的缓存")
    @PostMapping(value = "/clearStoreSubject", produces = "application/json; charset=UTF-8")
    public R<Object> clearStoreSubject() {
        redisService.setNullLike(RedisParam.MAIN_SUBJECT);
        redisService.setNullLike(RedisParam.CHILD_SUBJECT);
        redisService.setNullLike(RedisParam.MAIN_COURSETYPE);
        redisService.setNullLike(RedisParam.CHILD_COURSETYPE);
        redisService.setNullLike(RedisParam.MAIN_TABLEDOWNLOADTYPE);
        redisService.setNullLike(RedisParam.CHILD_TABLEDOWNLOADTYPE);

        return R.ok();
    }

    @ApiOperation(value = "清空加盟店的数据缓存")
    @PostMapping(value = "/clearStoreData", produces = "application/json; charset=UTF-8")
    public R<Object> clearStoreData() {
        redisService.setNullLike(RedisParam.STORE_DATA);
        redisService.setNullLike(RedisParam.STORE_DATA_SERVICE);
        redisService.setNullLike(RedisParam.STORE_DATA_KINDS);
        redisService.setNullLike(RedisParam.STORE_MEMBERS);
        redisService.setNullLike(RedisParam.STORE_CHANNEL);
        redisService.setNullLike(RedisParam.STORE_SOURCE_CHANNEL);
        redisService.setNullLike(RedisParam.CORP_TEACHER);

        return R.ok();
    }

    @ApiOperation(value = "清空门店员工的登录信息")
    @PostMapping(value = "/clearStaffLoginInfo", produces = "application/json; charset=UTF-8")
    public R<Object> clearStaffLoginInfo() {
        redisService.setNullLike(RedisParam.STAFF_LOGIN);

        return R.ok();
    }

}
